home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DBSHOW.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-23
|
5KB
|
176 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: dbshow.cpp
// Title: Application Template
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains the program entry point for
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <dbase.hpp>
//----------------------------------------------------------------------------
// Stack size
//----------------------------------------------------------------------------
#if COMPILER_BORLAND && (OS_DOS || OS_WINDOWS)
unsigned _stklen = 0x4000;
#endif
//----------------------------------------------------------------------------
// Globals
//----------------------------------------------------------------------------
//
// A useless string which is simply embedded in the executable.
//
PSZ __pszCredits__ = "Written by John M Weeder, 1993";
//
// This should contain a program description which will be displayed as
// part of the program's help text.
//
static PCSZ pcszDescription =
"This program displays the contents of a dBase file.";
//
// Program command line options
//
static LONG lStart = 1;
static LONG lEnd = -1;
static LONG lLength = -1;
static CHAR szInput[MAX_PATH];
static BS_CMDOPT acmdopt[] =
{
{ "BEGIN", (PVOID)&lStart, CMDOPT_NUMERIC, "First record to display."},
{ "END", (PVOID)&lEnd, CMDOPT_NUMERIC, "Last record to display."},
{ "LENGTH", (PVOID)&lLength, CMDOPT_NUMERIC, "Number of records to display."},
{ "filename", (PVOID)szInput, CMDOPT_FILESPECR(80),"File name."},
BS_CMDOPT_NULL,
};
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
static VOID FN_L Display(RDB_DBASE db)
{
SIZET cFields = db.Fields();
LONG FN_M Record();
Output("Record # %ld:\n", db.Record());
for (SIZET i = 1; i <= cFields; ++i)
{
DB_FLD fld(&db, i);
Output(" %2d) %-15.15s %c %3d : %-45.45s\n",
i, fld.Name(), fld.Type(), fld.Len(),
(fld.Type() == 'M' ? "*** Memo Field ***": (PCSZ)fld));
}
Output("\n");
return ;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
static SHORT FN_L Process(void)
{
DB_DBASE db;
if (!db.Open(szInput))
return FALSE;
LONG lRecords = db.Records();
Output("Opened '%s' (%ld records)\n", szInput, lRecords);
if (lRecords == 0)
return TRUE;
if (lStart < 1)
lStart = 1;
if (lStart > lRecords)
lStart = lRecords;
if (lLength > 0)
lEnd = lStart + lLength - 1;
if (lEnd > lRecords || lEnd < lStart)
lEnd = lRecords;
for (; lStart <= lEnd; ++lStart)
{
if (!db.Go(lStart))
return FALSE;
Display(db);
db.Unlock();
}
return TRUE;
}
//----------------------------------------------------------------------------
// Description: main() - Program entry point
// Parameters: Standard C parameters
// Returns: DOS return code.
//----------------------------------------------------------------------------
int main(int argc, char **argv)
{
static BS_CFG cfg = CFG_DFT;
BOOL fResult;
//
// Initialize base library
//
BaseLibraryInitialize(argc, argv, &cfg);
BaseTitle("$Revision: 93.1 $", __DATE__, __TIME__, "dBase File Viewer Utility");
if (!BaseTitleHelp(acmdopt, pcszDescription))
return 99;
if (DB_DBASE::Start())
{
fResult = Process();
DB_DBASE::Terminate();
}
Output(fResult ? "Success.\n": "Failed\n");
return fResult ? 0: 99;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------